<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <div id="app">
      <div>欢迎光临_vue开发的收银系统_水果店</div>
      <table border="1">
        <thead>
          <tr>
            <th>苹果 {{ price }} ￥ / 斤，折扣 < {{ discount * 10 }} 折 ></th>
          </tr>
        </thead>
        <tbody>
          <tr>
            <td>请输入你要购买的斤数 <input id="countInput" type="number" :value="count" /></td>
          </tr>
          <tr>
            <td>
              <button @click="buy">结账买单~</button>
            </td>
          </tr>
          <tr>
            <td>{{ totalText }}</td>
          </tr>
        </tbody>
      </div>
    </table>

    <script src="./vue.js"></script>
    <script>
      new Vue({
        el: '#app',
        data: {
          price: 10,
          discount: 0.8,
          count: '1'
        },
        computed: {
          totalText() {

            const a = this.price * this.count
            const b = a * this.discount

            return `结账单：总价：${ a } ￥ 元 折后价：${ b } ￥ 元 省了：${ a - b } ￥ 元`
          }
        },
        methods: {
          buy() {
            // 1. 获取输入框中最新的值
            // 2. 赋值给 count 数据
            const count = document.querySelector('#countInput').value.trim()
            if (count === '') return
            this.count = +count
          }
        }
      })
    </script>
  </body>
</html>
